Each component is located in its own directory, named Component.wo, and generally contains these parts:
Typically, components contain some form of the three files shown in Figure 1; however, any given component might contain more or fewer files. For example, components whose code is written in a compiled language do not contain code files. A component may not need a code file at all; it may need only a template file and a declarations file. Another component might have a code file but no template file or declarations file. Plus, if you create a component using Project Builder or WebObjects Builder, you'll get a fourth file, Component.api, which contains API that should be made public to other components.
The next three sections describe more completely these template, code, and declarations files.
An HTML template can also contain a reference to another component (called a reusable component or subcomponent) that represents a portion of an HTML page. This reference behaves just like a reference to a dynamic element.
With WebObjects, you can write your code file in one of three programming languages: Java, Objective-C, or WebScript. Java is the language of choice for many people; others prefer Objective-C. Because both of these languages require compiling, they aren't as well suited to rapid prototyping as a scripting language is. For this reason WebObjects provides a scripting language named WebScript, described in the chapter "The WebScript Language". You may have noticed that the examples directory mentioned previously offers examples in all three languages.
Note: Java support is not available on the Mach or HP-UX platform.
The Main.wo component shown in Figure 1 uses a WebScript file to define its behavior. (The .wos extension signifies WebScript.) If you want to use Java or Objective-C, the code file resides at the same level as the Main.wo directory as shown in Figure 2. (In Project Builder, Java and Objective-C code files are shown under Classes instead of with the component under Web Components.)
You can mix languages. It's common to use WebScript to write your interface logic (that is, the files described in this chapter) and use Java or Objective-C to write your business logic. Many simple applications are written entirely in WebScript. Some programmers prototype using WebScript and then create a compiled version of the same application to improve performance.
Table of Contents
Next Section